package cn.example.game.db.dao;
import org.artifact.core.db.JedisDao;
import org.artifact.core.lang.StrPlus;
import redis.clients.jedis.Pipeline;
import org.artifact.core.context.bytebuf.IByteBuff;
import org.artifact.core.context.bytebuf.IByteBuffFactory;
import redis.clients.jedis.Jedis;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Set;
import org.artifact.core.lang.IServer;
import java.util.function.BiFunction;
import org.artifact.core.db.BaseBean;
import cn.hutool.core.map.MapUtil;
import java.util.HashMap;
import org.artifact.core.db.BaseDao;
import cn.example.game.db.bean.ServerMail;
import static cn.hutool.core.util.ObjectUtil.equal;

public abstract class ServerMailDAO extends JedisDao<ServerMail>{
	@Override
	protected String getDBName() {
		return "example_game";
	}
	
	@Override
	protected String getTableName() {
		return "t_server_mail";
	}
	
	@Override
	protected Class<ServerMail> getEntityClass(){
		return ServerMail.class;
	}
	
	@Override
	protected ServerMail createEntity() {
		return new ServerMail() {};
	}

	@Override
	protected String getPKFieldName() {
		return "id";
	}
	
	// 根据主键导出
	public Map<String,Object> exportByPrimaryKey(long id,BiFunction<BaseDao,BaseBean,Object> function){
		return export(findByPrimaryKey(id),function);
	}
	
	
	public Map<String,Object> export(ServerMail serverMail,BiFunction<BaseDao,BaseBean,Object> function){
		Map<String,Object> data = new HashMap<>();
		data.put("self", function.apply(this,serverMail));
		return data;
	}
	
	public List<Map<String,Object>> export(List<ServerMail> serverMails,BiFunction<BaseDao,BaseBean,Object> function){
		List<Map<String,Object>> data = new ArrayList<>();
		for(ServerMail serverMail : serverMails){
			data.add(export(serverMail,function));
		}
		return data;
	}


	public ServerMail _import(Map<String,Object> data,BiFunction<BaseDao,Map,BaseBean> function){
	    ServerMail serverMail = createEntity();
	    serverMail = (ServerMail)function.apply(this,MapUtil.get(data,"self",Map.class));

        return serverMail;
    }

    public List<ServerMail> _import(List<Map<String,Object>> data,BiFunction<BaseDao,Map,BaseBean> function){
        List<ServerMail> list = new ArrayList<>();
        for(Map<String,Object> map : data){
            list.add(_import(map,function));
        }
        return list;
    }
	
	

	protected String[] getIndexKey(ServerMail t){
		String[] indexKeys = new String[0];
		return indexKeys;
	}
	
	protected void addIndex(Pipeline p,ServerMail t){
		String[] keys = indexKeys.get(t.pk());
		if(keys == null){
			keys= getIndexKey(t);
		}
	}
	
	protected void removeIndex(Pipeline p,ServerMail t){
		String[] keys = indexKeys.get(t.pk());
		if(keys == null){
			keys= getIndexKey(t);
		}
	}
	

}